package com.neusoft.resturant.controller;

import com.neusoft.resturant.common.utils.R;
import com.neusoft.resturant.entity.ResCarts;
import com.neusoft.resturant.entity.ResCollect;
import com.neusoft.resturant.service.IResCartsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: resturant
 * @description:
 * @author: lydms
 * @create: 2023-12-16 20:05
 **/


@RestController
@RequestMapping("/api/carts")
public class ResCartsController extends BaseController{


    @Autowired
    private IResCartsService resCartsService;

    /**
     * 列表查询
     * @param resCarts
     * @return
     */
    @GetMapping("/list")
    public R list(ResCarts resCarts) {
        resCarts.setUser_id(this.getUserId());
        List<ResCollect> list = resCartsService.selectResCartsList();
        return R.success(list);
    }

    /**
     * 加购物车商品
     * @return
     */
    @PostMapping("/add")
    public R addResCarts(@RequestBody  ResCarts resCarts){
        resCarts.setUser_id(this.getUserId());
        resCartsService.addResCart(resCarts);
        return R.success("添加成功");
    }


    /**
     * 删除购物车的菜品
     * @param ids
     * @return
     */
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable Long[] ids)
    {
        resCartsService.deleteResCartsByIds(ids);
        return R.success("删除成功");
    }

}
